﻿using Baby.GrowUp.Data;

namespace Baby.GrowUp.Model
{
    /// <summary>
    /// 用户
    /// </summary>
    public class Users
    {
        #region 属性
        /// <summary>
        /// 用户ID
        /// </summary>
        [DataProperty("U_Id")]
        public string U_Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [DataProperty("U_UserName")]
        public string U_UserName { get; set; }

        /// <summary>
        /// 用户昵称
        /// </summary>
        [DataProperty("U_NickName")]
        public string U_NickName { get; set; }

        /// <summary>
        /// 用户真实姓名
        /// </summary>
        [DataProperty("U_RealName")]
        public string U_RealName { get; set; }

        /// <summary>
        /// 用户登录密码
        /// </summary>
        [DataProperty("U_Password")]
        public string U_Password { get; set; }

        /// <summary>
        /// 用户明细信息ID
        /// </summary>
        [DataProperty("D_Id")]
        public string D_Id { get; set; }
        #endregion

        #region 根据用户名获取用户
        /// <summary>
        /// 根据用户名获取用户
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static Users GetUserByUserName(string userName)
        {
            using (SqlDbConnection con = SqlDbConnection.Connect())
            {
                con.CommandText = "select * from Users where U_UserName = @uname";
                con.AddParameters("uname", userName);
                return con.ToObject<Users>();
            }
        }
        #endregion

        #region 根据用户名获取用户
        /// <summary>
        /// 根据用户名获取用户
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public static Users GetUserByUserId(string uid)
        {
            using (SqlDbConnection con = SqlDbConnection.Connect())
            {
                con.CommandText = "select * from Users where U_Id = @uid";
                con.AddParameters("uid", uid);
                return con.ToObject<Users>();
            }
        }
        #endregion
    }
}
